package com.wushi.lenovo.asia5b.app_ui.other.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.mvp.base.BaseAppCompatActivity;
import com.mvp.base.BaseFragmentPagerAdapter;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_ui.other.fragment.PhotoPreviewFragment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.wushi.lenovo.asia5b.app_config.CommonConstant.PHOTO_PREVIEW_DATAS;

/**
 * Created by zhangyuncai on 2019/3/16.
 */
public class PhotoPreviewActivity extends BaseAppCompatActivity {
    public static void startPhotoViewActivity(Context context, String imgUrl) {
        List<String> imgUrls = new ArrayList<>();
        imgUrls.add(imgUrl);
        startPhotoViewActivity(context, imgUrls);
    }

    public static void startPhotoViewActivity(Context context, List<String> imgUrls) {
        Intent intent = new Intent(context, PhotoPreviewActivity.class);
        intent.putExtra(PHOTO_PREVIEW_DATAS, (Serializable) imgUrls);
        context.startActivity(intent);
    }

    @BindView(R.id.vp_photopreview)
    ViewPager mViewPager;
    private List<String> imgUrls;
    private BaseFragmentPagerAdapter mAdapter;

    @Override
    protected int getLayoutId() {
        setStatusTrans();
        return R.layout.activity_photopreview;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        imgUrls = (List<String>) getIntent().getSerializableExtra(PHOTO_PREVIEW_DATAS);
        if (imgUrls == null) {
            imgUrls = new ArrayList<>();
            imgUrls.add("");
        }
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        List<Fragment> fragments = new ArrayList<>();
        for (String imgUrl : imgUrls) {
            fragments.add(PhotoPreviewFragment.newInstance(this, imgUrl));
        }
        mAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), fragments, null);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(3);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }
}
